export class WhiteListManager
{
    // static whitelist:string[]=[];
    static  InitWhiteList()
    {
        if(!(Memory as any).whitelist)
        {
            (Memory as any).whitelist = new Array<string>();
        }
        if(!(Memory as any).foelist)
        {
            (Memory as any).foelist = new Array<string>();
        }

        this.AddWhiteList("touchfish");
        this.AddWhiteList("Lampese");

    }
    /**
     * 添加仇人
     * @param name
     */
    static AddFoe(name:string)
    {
        const val=this.whitelist.find(item=>item==name);
        if(val)
        {
            return ;
        }
        if(!this.foelist.find(item=>item==name))
        {
            this.foelist.push(name);
        }
    }

    /**
     * 移除仇人
     * @param name
     */
    static RemoveFoe(name:string)
    {
        _.remove(this.foelist,(n)=>{return n==name});
    }

    static AddWhiteList(name:string)
    {
        if(!this.whitelist.find(item=>item==name))
        {
            this.whitelist.push(name);
        }
    }

    static RemoveWhiteList(name:string)
    {
        _.remove(this.whitelist,(n)=>{return n==name});
    }
    static IsFoeCreep(creep:Creep)
    {
        if(this.foelist.findIndex(item=>item==creep.owner.username)>-1)
        {
            // 在黑名单里
            return true;
        }
        return false;
    }
    static IsFriendCreep(creep:Creep)
    {
        if(this.foelist.findIndex(item=>item==creep.owner.username)>-1)
        {
            // 在黑名单里
            return false;
        }
        const val=this.whitelist.find(item=>item==creep.owner.username);
        Memory.Debug[`whitelist  `] = this.whitelist;
        if(val)
        {
            Memory.Debug[`Is Friend ${creep.owner.username}`] = "是好友";
            return true;
        }
        return false;
    }
    static IsFriend(userName:string)
    {
        if(userName == global.UserName)
        {
            return true;
        }
        const val=this.whitelist.find(item=>item==userName);
        Memory.Debug[`whitelist  `] = this.whitelist;
        if(val)
        {
            Memory.Debug[`Is Friend ${userName}`] = "是好友";
            return true;
        }
        return false;
    }
    private static  get whitelist():Array<string>
    {
        return  (Memory as any).whitelist;
    }

    private static  get foelist():Array<string>
    {
        return  (Memory as any).foelist;
    }
}
